In [2]:
pip install folium
Collecting folium
  Downloading folium-0.16.0-py2.py3-none-any.whl.metadata (3.6 kB)
Collecting branca>=0.6.0 (from folium)
  Downloading branca-0.7.1-py3-none-any.whl.metadata (1.5 kB)
Requirement already satisfied: jinja2>=2.9 in c:\users\mvair\anaconda3\lib\site-packages (from folium) (3.1.3)
Requirement already satisfied: numpy in c:\users\mvair\anaconda3\lib\site-packages (from folium) (1.26.4)
Requirement already satisfied: requests in c:\users\mvair\anaconda3\lib\site-packages (from folium) (2.31.0)
Requirement already satisfied: xyzservices in c:\users\mvair\anaconda3\lib\site-packages (from folium) (2022.9.0)
Requirement already satisfied: MarkupSafe>=2.0 in c:\users\mvair\anaconda3\lib\site-packages (from jinja2>=2.9->folium) (2.1.3)
Requirement already satisfied: charset-normalizer<4,>=2 in c:\users\mvair\anaconda3\lib\site-packages (from requests->folium) (2.0.4)
Requirement already satisfied: idna<4,>=2.5 in c:\users\mvair\anaconda3\lib\site-packages (from requests->folium) (3.4)
Requirement already satisfied: urllib3<3,>=1.21.1 in c:\users\mvair\anaconda3\lib\site-packages (from requests->folium) (2.0.7)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\mvair\anaconda3\lib\site-packages (from requests->folium) (2024.2.2)
Downloading folium-0.16.0-py2.py3-none-any.whl (100 kB)
   ---------------------------------------- 0.0/100.0 kB ? eta -:--:--
   ---- ----------------------------------- 10.2/100.0 kB ? eta -:--:--
   ------------------------------------ --- 92.2/100.0 kB 1.3 MB/s eta 0:00:01
   ---------------------------------------- 100.0/100.0 kB 1.4 MB/s eta 0:00:00
Downloading branca-0.7.1-py3-none-any.whl (25 kB)
Installing collected packages: branca, folium
Successfully installed branca-0.7.1 folium-0.16.0
Note: you may need to restart the kernel to use updated packages.
In [3]:
import folium

m = folium.Map(location=[51.5074, -0.1278], zoom_start=10)

folium.Marker(
    location=[51.5074, -0.1278],
    popup="London",
    icon=folium.Icon(color="blue")
).add_to(m)

m
Out[3]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [4]:
pip install osmnx 
Collecting osmnx
  Downloading osmnx-1.9.1-py3-none-any.whl.metadata (4.9 kB)
Collecting geopandas>=0.12 (from osmnx)
  Using cached geopandas-0.14.3-py3-none-any.whl.metadata (1.5 kB)
Requirement already satisfied: networkx>=2.5 in c:\users\mvair\anaconda3\lib\site-packages (from osmnx) (3.1)
Requirement already satisfied: numpy>=1.20 in c:\users\mvair\anaconda3\lib\site-packages (from osmnx) (1.26.4)
Requirement already satisfied: pandas>=1.1 in c:\users\mvair\anaconda3\lib\site-packages (from osmnx) (2.1.4)
Requirement already satisfied: requests>=2.27 in c:\users\mvair\anaconda3\lib\site-packages (from osmnx) (2.31.0)
Collecting shapely>=2.0 (from osmnx)
  Using cached shapely-2.0.3-cp311-cp311-win_amd64.whl.metadata (7.2 kB)
Collecting fiona>=1.8.21 (from geopandas>=0.12->osmnx)
  Downloading fiona-1.9.6-cp311-cp311-win_amd64.whl.metadata (51 kB)
     ---------------------------------------- 0.0/51.5 kB ? eta -:--:--
     ------------------------------ ------- 41.0/51.5 kB 960.0 kB/s eta 0:00:01
     -------------------------------------- 51.5/51.5 kB 878.6 kB/s eta 0:00:00
Requirement already satisfied: packaging in c:\users\mvair\anaconda3\lib\site-packages (from geopandas>=0.12->osmnx) (23.1)
Collecting pyproj>=3.3.0 (from geopandas>=0.12->osmnx)
  Using cached pyproj-3.6.1-cp311-cp311-win_amd64.whl.metadata (31 kB)
Requirement already satisfied: python-dateutil>=2.8.2 in c:\users\mvair\anaconda3\lib\site-packages (from pandas>=1.1->osmnx) (2.8.2)
Requirement already satisfied: pytz>=2020.1 in c:\users\mvair\anaconda3\lib\site-packages (from pandas>=1.1->osmnx) (2023.3.post1)
Requirement already satisfied: tzdata>=2022.1 in c:\users\mvair\anaconda3\lib\site-packages (from pandas>=1.1->osmnx) (2023.3)
Requirement already satisfied: charset-normalizer<4,>=2 in c:\users\mvair\anaconda3\lib\site-packages (from requests>=2.27->osmnx) (2.0.4)
Requirement already satisfied: idna<4,>=2.5 in c:\users\mvair\anaconda3\lib\site-packages (from requests>=2.27->osmnx) (3.4)
Requirement already satisfied: urllib3<3,>=1.21.1 in c:\users\mvair\anaconda3\lib\site-packages (from requests>=2.27->osmnx) (2.0.7)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\mvair\anaconda3\lib\site-packages (from requests>=2.27->osmnx) (2024.2.2)
Requirement already satisfied: attrs>=19.2.0 in c:\users\mvair\anaconda3\lib\site-packages (from fiona>=1.8.21->geopandas>=0.12->osmnx) (23.1.0)
Requirement already satisfied: click~=8.0 in c:\users\mvair\anaconda3\lib\site-packages (from fiona>=1.8.21->geopandas>=0.12->osmnx) (8.1.7)
Collecting click-plugins>=1.0 (from fiona>=1.8.21->geopandas>=0.12->osmnx)
  Using cached click_plugins-1.1.1-py2.py3-none-any.whl.metadata (6.4 kB)
Collecting cligj>=0.5 (from fiona>=1.8.21->geopandas>=0.12->osmnx)
  Using cached cligj-0.7.2-py3-none-any.whl.metadata (5.0 kB)
Requirement already satisfied: six in c:\users\mvair\anaconda3\lib\site-packages (from fiona>=1.8.21->geopandas>=0.12->osmnx) (1.16.0)
Requirement already satisfied: colorama in c:\users\mvair\anaconda3\lib\site-packages (from click~=8.0->fiona>=1.8.21->geopandas>=0.12->osmnx) (0.4.6)
Downloading osmnx-1.9.1-py3-none-any.whl (104 kB)
   ---------------------------------------- 0.0/104.3 kB ? eta -:--:--
   ---------------------------------------- 104.3/104.3 kB 5.9 MB/s eta 0:00:00
Using cached geopandas-0.14.3-py3-none-any.whl (1.1 MB)
Using cached shapely-2.0.3-cp311-cp311-win_amd64.whl (1.4 MB)
Downloading fiona-1.9.6-cp311-cp311-win_amd64.whl (22.9 MB)
   ---------------------------------------- 0.0/22.9 MB ? eta -:--:--
    --------------------------------------- 0.4/22.9 MB 12.9 MB/s eta 0:00:02
   - -------------------------------------- 0.6/22.9 MB 7.4 MB/s eta 0:00:04
   - -------------------------------------- 0.9/22.9 MB 7.9 MB/s eta 0:00:03
   - -------------------------------------- 1.1/22.9 MB 7.2 MB/s eta 0:00:04
   -- ------------------------------------- 1.3/22.9 MB 7.0 MB/s eta 0:00:04
   -- ------------------------------------- 1.5/22.9 MB 6.2 MB/s eta 0:00:04
   -- ------------------------------------- 1.6/22.9 MB 5.7 MB/s eta 0:00:04
   --- ------------------------------------ 1.8/22.9 MB 5.7 MB/s eta 0:00:04
   --- ------------------------------------ 1.9/22.9 MB 5.4 MB/s eta 0:00:04
   --- ------------------------------------ 2.1/22.9 MB 5.4 MB/s eta 0:00:04
   --- ------------------------------------ 2.3/22.9 MB 5.2 MB/s eta 0:00:05
   ---- ----------------------------------- 2.4/22.9 MB 5.0 MB/s eta 0:00:05
   ---- ----------------------------------- 2.6/22.9 MB 5.0 MB/s eta 0:00:05
   ---- ----------------------------------- 2.7/22.9 MB 4.8 MB/s eta 0:00:05
   ----- ---------------------------------- 2.9/22.9 MB 4.9 MB/s eta 0:00:05
   ----- ---------------------------------- 3.0/22.9 MB 4.7 MB/s eta 0:00:05
   ----- ---------------------------------- 3.2/22.9 MB 4.6 MB/s eta 0:00:05
   ----- ---------------------------------- 3.4/22.9 MB 4.7 MB/s eta 0:00:05
   ------ --------------------------------- 3.5/22.9 MB 4.6 MB/s eta 0:00:05
   ------ --------------------------------- 3.7/22.9 MB 4.6 MB/s eta 0:00:05
   ------ --------------------------------- 3.8/22.9 MB 4.5 MB/s eta 0:00:05
   ------ --------------------------------- 4.0/22.9 MB 4.5 MB/s eta 0:00:05
   ------- -------------------------------- 4.1/22.9 MB 4.5 MB/s eta 0:00:05
   ------- -------------------------------- 4.3/22.9 MB 4.5 MB/s eta 0:00:05
   ------- -------------------------------- 4.5/22.9 MB 4.5 MB/s eta 0:00:05
   -------- ------------------------------- 4.6/22.9 MB 4.4 MB/s eta 0:00:05
   -------- ------------------------------- 4.8/22.9 MB 4.4 MB/s eta 0:00:05
   -------- ------------------------------- 4.9/22.9 MB 4.4 MB/s eta 0:00:05
   -------- ------------------------------- 5.1/22.9 MB 4.4 MB/s eta 0:00:05
   --------- ------------------------------ 5.3/22.9 MB 4.3 MB/s eta 0:00:05
   --------- ------------------------------ 5.5/22.9 MB 4.3 MB/s eta 0:00:05
   --------- ------------------------------ 5.6/22.9 MB 4.3 MB/s eta 0:00:04
   ---------- ----------------------------- 5.8/22.9 MB 4.3 MB/s eta 0:00:04
   ---------- ----------------------------- 5.9/22.9 MB 4.3 MB/s eta 0:00:04
   ---------- ----------------------------- 6.1/22.9 MB 4.3 MB/s eta 0:00:04
   ---------- ----------------------------- 6.3/22.9 MB 4.3 MB/s eta 0:00:04
   ----------- ---------------------------- 6.4/22.9 MB 4.2 MB/s eta 0:00:04
   ----------- ---------------------------- 6.6/22.9 MB 4.2 MB/s eta 0:00:04
   ----------- ---------------------------- 6.7/22.9 MB 4.2 MB/s eta 0:00:04
   ------------ --------------------------- 6.9/22.9 MB 4.2 MB/s eta 0:00:04
   ------------ --------------------------- 7.0/22.9 MB 4.2 MB/s eta 0:00:04
   ------------ --------------------------- 7.2/22.9 MB 4.2 MB/s eta 0:00:04
   ------------ --------------------------- 7.4/22.9 MB 4.2 MB/s eta 0:00:04
   ------------- -------------------------- 7.5/22.9 MB 4.2 MB/s eta 0:00:04
   ------------- -------------------------- 7.7/22.9 MB 4.2 MB/s eta 0:00:04
   ------------- -------------------------- 7.9/22.9 MB 4.2 MB/s eta 0:00:04
   -------------- ------------------------- 8.0/22.9 MB 4.2 MB/s eta 0:00:04
   -------------- ------------------------- 8.2/22.9 MB 4.2 MB/s eta 0:00:04
   -------------- ------------------------- 8.3/22.9 MB 4.2 MB/s eta 0:00:04
   -------------- ------------------------- 8.5/22.9 MB 4.2 MB/s eta 0:00:04
   --------------- ------------------------ 8.7/22.9 MB 4.1 MB/s eta 0:00:04
   --------------- ------------------------ 8.8/22.9 MB 4.1 MB/s eta 0:00:04
   --------------- ------------------------ 9.0/22.9 MB 4.1 MB/s eta 0:00:04
   --------------- ------------------------ 9.1/22.9 MB 4.1 MB/s eta 0:00:04
   ---------------- ----------------------- 9.3/22.9 MB 4.1 MB/s eta 0:00:04
   ---------------- ----------------------- 9.5/22.9 MB 4.1 MB/s eta 0:00:04
   ---------------- ----------------------- 9.6/22.9 MB 4.1 MB/s eta 0:00:04
   ----------------- ---------------------- 9.8/22.9 MB 4.1 MB/s eta 0:00:04
   ----------------- ---------------------- 9.9/22.9 MB 4.1 MB/s eta 0:00:04
   ----------------- ---------------------- 10.1/22.9 MB 4.1 MB/s eta 0:00:04
   ----------------- ---------------------- 10.2/22.9 MB 4.1 MB/s eta 0:00:04
   ------------------ --------------------- 10.4/22.9 MB 4.0 MB/s eta 0:00:04
   ------------------ --------------------- 10.5/22.9 MB 4.0 MB/s eta 0:00:04
   ------------------ --------------------- 10.6/22.9 MB 3.9 MB/s eta 0:00:04
   ------------------ --------------------- 10.8/22.9 MB 3.9 MB/s eta 0:00:04
   ------------------- -------------------- 11.0/22.9 MB 3.9 MB/s eta 0:00:04
   ------------------- -------------------- 11.2/22.9 MB 3.9 MB/s eta 0:00:04
   ------------------- -------------------- 11.3/22.9 MB 3.9 MB/s eta 0:00:03
   -------------------- ------------------- 11.5/22.9 MB 3.9 MB/s eta 0:00:03
   -------------------- ------------------- 11.6/22.9 MB 3.9 MB/s eta 0:00:03
   -------------------- ------------------- 11.8/22.9 MB 3.9 MB/s eta 0:00:03
   -------------------- ------------------- 11.9/22.9 MB 3.9 MB/s eta 0:00:03
   --------------------- ------------------ 12.1/22.9 MB 3.9 MB/s eta 0:00:03
   --------------------- ------------------ 12.2/22.9 MB 3.9 MB/s eta 0:00:03
   --------------------- ------------------ 12.4/22.9 MB 3.9 MB/s eta 0:00:03
   --------------------- ------------------ 12.6/22.9 MB 3.9 MB/s eta 0:00:03
   ---------------------- ----------------- 12.8/22.9 MB 3.9 MB/s eta 0:00:03
   ---------------------- ----------------- 12.9/22.9 MB 3.9 MB/s eta 0:00:03
   ---------------------- ----------------- 13.0/22.9 MB 3.9 MB/s eta 0:00:03
   ----------------------- ---------------- 13.3/22.9 MB 3.9 MB/s eta 0:00:03
   ----------------------- ---------------- 13.4/22.9 MB 3.9 MB/s eta 0:00:03
   ----------------------- ---------------- 13.6/22.9 MB 3.9 MB/s eta 0:00:03
   ------------------------ --------------- 13.8/22.9 MB 3.9 MB/s eta 0:00:03
   ------------------------ --------------- 13.9/22.9 MB 3.9 MB/s eta 0:00:03
   ------------------------ --------------- 14.1/22.9 MB 3.9 MB/s eta 0:00:03
   ------------------------ --------------- 14.3/22.9 MB 3.9 MB/s eta 0:00:03
   ------------------------- -------------- 14.4/22.9 MB 3.9 MB/s eta 0:00:03
   ------------------------- -------------- 14.6/22.9 MB 3.9 MB/s eta 0:00:03
   ------------------------- -------------- 14.7/22.9 MB 3.9 MB/s eta 0:00:03
   -------------------------- ------------- 14.9/22.9 MB 3.9 MB/s eta 0:00:03
   -------------------------- ------------- 15.1/22.9 MB 3.9 MB/s eta 0:00:03
   -------------------------- ------------- 15.2/22.9 MB 3.9 MB/s eta 0:00:02
   -------------------------- ------------- 15.3/22.9 MB 3.9 MB/s eta 0:00:02
   --------------------------- ------------ 15.5/22.9 MB 3.9 MB/s eta 0:00:02
   --------------------------- ------------ 15.7/22.9 MB 3.9 MB/s eta 0:00:02
   --------------------------- ------------ 15.8/22.9 MB 3.9 MB/s eta 0:00:02
   --------------------------- ------------ 16.0/22.9 MB 3.9 MB/s eta 0:00:02
   ---------------------------- ----------- 16.1/22.9 MB 3.9 MB/s eta 0:00:02
   ---------------------------- ----------- 16.3/22.9 MB 3.9 MB/s eta 0:00:02
   ---------------------------- ----------- 16.5/22.9 MB 3.9 MB/s eta 0:00:02
   ---------------------------- ----------- 16.5/22.9 MB 3.8 MB/s eta 0:00:02
   ---------------------------- ----------- 16.6/22.9 MB 3.8 MB/s eta 0:00:02
   ----------------------------- ---------- 16.7/22.9 MB 3.8 MB/s eta 0:00:02
   ----------------------------- ---------- 16.7/22.9 MB 3.7 MB/s eta 0:00:02
   ----------------------------- ---------- 16.8/22.9 MB 3.7 MB/s eta 0:00:02
   ----------------------------- ---------- 16.8/22.9 MB 3.7 MB/s eta 0:00:02
   ----------------------------- ---------- 16.9/22.9 MB 3.6 MB/s eta 0:00:02
   ------------------------------ --------- 17.3/22.9 MB 3.6 MB/s eta 0:00:02
   ------------------------------ --------- 17.4/22.9 MB 3.5 MB/s eta 0:00:02
   ------------------------------ --------- 17.5/22.9 MB 3.5 MB/s eta 0:00:02
   ------------------------------ --------- 17.7/22.9 MB 3.5 MB/s eta 0:00:02
   ------------------------------- -------- 18.0/22.9 MB 3.5 MB/s eta 0:00:02
   ------------------------------- -------- 18.2/22.9 MB 3.4 MB/s eta 0:00:02
   -------------------------------- ------- 18.4/22.9 MB 3.4 MB/s eta 0:00:02
   -------------------------------- ------- 18.7/22.9 MB 3.4 MB/s eta 0:00:02
   -------------------------------- ------- 18.9/22.9 MB 3.4 MB/s eta 0:00:02
   --------------------------------- ------ 19.3/22.9 MB 3.4 MB/s eta 0:00:02
   ---------------------------------- ----- 19.6/22.9 MB 3.4 MB/s eta 0:00:01
   ---------------------------------- ----- 19.8/22.9 MB 3.4 MB/s eta 0:00:01
   ----------------------------------- ---- 20.1/22.9 MB 3.4 MB/s eta 0:00:01
   ----------------------------------- ---- 20.3/22.9 MB 3.4 MB/s eta 0:00:01
   ----------------------------------- ---- 20.4/22.9 MB 3.4 MB/s eta 0:00:01
   ------------------------------------ --- 20.7/22.9 MB 3.4 MB/s eta 0:00:01
   ------------------------------------ --- 20.9/22.9 MB 3.4 MB/s eta 0:00:01
   ------------------------------------ --- 21.0/22.9 MB 3.5 MB/s eta 0:00:01
   ------------------------------------- -- 21.2/22.9 MB 3.4 MB/s eta 0:00:01
   ------------------------------------- -- 21.4/22.9 MB 3.4 MB/s eta 0:00:01
   ------------------------------------- -- 21.7/22.9 MB 3.4 MB/s eta 0:00:01
   -------------------------------------- - 21.9/22.9 MB 3.4 MB/s eta 0:00:01
   -------------------------------------- - 22.2/22.9 MB 3.4 MB/s eta 0:00:01
   ---------------------------------------  22.4/22.9 MB 3.4 MB/s eta 0:00:01
   ---------------------------------------  22.5/22.9 MB 3.4 MB/s eta 0:00:01
   ---------------------------------------  22.8/22.9 MB 3.4 MB/s eta 0:00:01
   ---------------------------------------  22.9/22.9 MB 3.5 MB/s eta 0:00:01
   ---------------------------------------- 22.9/22.9 MB 3.3 MB/s eta 0:00:00
Using cached pyproj-3.6.1-cp311-cp311-win_amd64.whl (6.1 MB)
Using cached click_plugins-1.1.1-py2.py3-none-any.whl (7.5 kB)
Using cached cligj-0.7.2-py3-none-any.whl (7.1 kB)
Installing collected packages: shapely, pyproj, cligj, click-plugins, fiona, geopandas, osmnx
Successfully installed click-plugins-1.1.1 cligj-0.7.2 fiona-1.9.6 geopandas-0.14.3 osmnx-1.9.1 pyproj-3.6.1 shapely-2.0.3
Note: you may need to restart the kernel to use updated packages.
In [9]:
pip install requests geopandas matplotlib
Requirement already satisfied: requests in c:\users\mvair\anaconda3\lib\site-packages (2.31.0)
Requirement already satisfied: geopandas in c:\users\mvair\anaconda3\lib\site-packages (0.14.3)
Requirement already satisfied: matplotlib in c:\users\mvair\anaconda3\lib\site-packages (3.8.0)
Requirement already satisfied: charset-normalizer<4,>=2 in c:\users\mvair\anaconda3\lib\site-packages (from requests) (2.0.4)
Requirement already satisfied: idna<4,>=2.5 in c:\users\mvair\anaconda3\lib\site-packages (from requests) (3.4)
Requirement already satisfied: urllib3<3,>=1.21.1 in c:\users\mvair\anaconda3\lib\site-packages (from requests) (2.0.7)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\mvair\anaconda3\lib\site-packages (from requests) (2024.2.2)
Requirement already satisfied: fiona>=1.8.21 in c:\users\mvair\anaconda3\lib\site-packages (from geopandas) (1.9.6)
Requirement already satisfied: packaging in c:\users\mvair\anaconda3\lib\site-packages (from geopandas) (23.1)
Requirement already satisfied: pandas>=1.4.0 in c:\users\mvair\anaconda3\lib\site-packages (from geopandas) (2.1.4)
Requirement already satisfied: pyproj>=3.3.0 in c:\users\mvair\anaconda3\lib\site-packages (from geopandas) (3.6.1)
Requirement already satisfied: shapely>=1.8.0 in c:\users\mvair\anaconda3\lib\site-packages (from geopandas) (2.0.3)
Requirement already satisfied: contourpy>=1.0.1 in c:\users\mvair\anaconda3\lib\site-packages (from matplotlib) (1.2.0)
Requirement already satisfied: cycler>=0.10 in c:\users\mvair\anaconda3\lib\site-packages (from matplotlib) (0.11.0)
Requirement already satisfied: fonttools>=4.22.0 in c:\users\mvair\anaconda3\lib\site-packages (from matplotlib) (4.25.0)
Requirement already satisfied: kiwisolver>=1.0.1 in c:\users\mvair\anaconda3\lib\site-packages (from matplotlib) (1.4.4)
Requirement already satisfied: numpy<2,>=1.21 in c:\users\mvair\anaconda3\lib\site-packages (from matplotlib) (1.26.4)
Requirement already satisfied: pillow>=6.2.0 in c:\users\mvair\anaconda3\lib\site-packages (from matplotlib) (10.2.0)
Requirement already satisfied: pyparsing>=2.3.1 in c:\users\mvair\anaconda3\lib\site-packages (from matplotlib) (3.0.9)
Requirement already satisfied: python-dateutil>=2.7 in c:\users\mvair\anaconda3\lib\site-packages (from matplotlib) (2.8.2)
Requirement already satisfied: attrs>=19.2.0 in c:\users\mvair\anaconda3\lib\site-packages (from fiona>=1.8.21->geopandas) (23.1.0)
Requirement already satisfied: click~=8.0 in c:\users\mvair\anaconda3\lib\site-packages (from fiona>=1.8.21->geopandas) (8.1.7)
Requirement already satisfied: click-plugins>=1.0 in c:\users\mvair\anaconda3\lib\site-packages (from fiona>=1.8.21->geopandas) (1.1.1)
Requirement already satisfied: cligj>=0.5 in c:\users\mvair\anaconda3\lib\site-packages (from fiona>=1.8.21->geopandas) (0.7.2)
Requirement already satisfied: six in c:\users\mvair\anaconda3\lib\site-packages (from fiona>=1.8.21->geopandas) (1.16.0)
Requirement already satisfied: pytz>=2020.1 in c:\users\mvair\anaconda3\lib\site-packages (from pandas>=1.4.0->geopandas) (2023.3.post1)
Requirement already satisfied: tzdata>=2022.1 in c:\users\mvair\anaconda3\lib\site-packages (from pandas>=1.4.0->geopandas) (2023.3)
Requirement already satisfied: colorama in c:\users\mvair\anaconda3\lib\site-packages (from click~=8.0->fiona>=1.8.21->geopandas) (0.4.6)
Note: you may need to restart the kernel to use updated packages.
In [20]:
import requests

def fetch_osm_data():
    api_url = "http://overpass-api.de/api/interpreter"
    query = """
    [out:json];
    (
      way["highway"]
      (50.746,7.154,50.748,7.156); // Replace with your bounding box
    );
    out body;
    """
    response = requests.post(api_url, data={'data': query})
    
    print("Status code:", response.status_code)
    try:
        data = response.json()
        return data
    except requests.exceptions.JSONDecodeError:
        print("Failed to decode JSON from response.")
        print(response.text[:500])
        return None

data = fetch_osm_data()
print(data)
Status code: 200
{'version': 0.6, 'generator': 'Overpass API 0.7.61.5 4133829e', 'osm3s': {'timestamp_osm_base': '2024-03-21T14:11:44Z', 'copyright': 'The data included in this document is from www.openstreetmap.org. The data is made available under ODbL.'}, 'elements': [{'type': 'way', 'id': 26577114, 'nodes': [291435953, 1751820952, 291435954, 1751820953, 1751820954, 1751820955, 291435955], 'tags': {'highway': 'residential', 'lit': 'yes', 'maxspeed': '30', 'maxspeed:type': 'DE:zone30', 'name': 'Rhedenstraße'}}, {'type': 'way', 'id': 26577115, 'nodes': [1558201814, 291435956], 'tags': {'highway': 'residential', 'maxspeed': '30', 'maxspeed:type': 'DE:zone30', 'name': 'Von-Ketteler-Straße'}}, {'type': 'way', 'id': 26577275, 'nodes': [291438870, 2580378582, 1647096049, 1579451712, 1558201822, 1558201815], 'tags': {'highway': 'residential', 'maxspeed': '30', 'maxspeed:type': 'DE:zone30', 'name': 'Mutter-Barat-Straße'}}, {'type': 'way', 'id': 26577276, 'nodes': [291438871, 291438872, 2580378571, 1647095991, 1647095994, 5633963168, 291438873], 'tags': {'highway': 'residential', 'lit': 'yes', 'maxspeed': '30', 'maxspeed:type': 'DE:zone30', 'name': 'Stegerwaldstraße', 'surface': 'asphalt'}}, {'type': 'way', 'id': 105196614, 'nodes': [1212226065, 1212226220, 4670199082, 4670199089], 'tags': {'access': 'private', 'highway': 'service', 'service': 'driveway'}}, {'type': 'way', 'id': 142380557, 'nodes': [1558201823, 4246007583, 1558201815, 4246007582, 1558201810, 1558201808, 1558201806, 1558201807, 1558201809, 1647096076, 1558201814, 1751820951, 1647096079, 291435953, 1558201813, 11717177703, 1558201812], 'tags': {'highway': 'residential', 'lit': 'yes', 'maxspeed': '30', 'maxspeed:type': 'DE:zone30', 'name': 'Von-Ketteler-Straße'}}, {'type': 'way', 'id': 142380558, 'nodes': [1558201806, 291435957, 1212226220, 291435958, 291435959], 'tags': {'bicycle': 'yes', 'foot': 'yes', 'highway': 'service', 'motorcar': 'private', 'motorcycle': 'private', 'name': 'Von-Ketteler-Straße', 'surface': 'asphalt'}}, {'type': 'way', 'id': 425280520, 'nodes': [4246007582, 4246007580], 'tags': {'highway': 'footway', 'surface': 'paving_stones'}}]}
In [17]:
import geopandas as gpd
from shapely.geometry import LineString

data = {'version': 0.6, 'generator': 'Overpass API 0.7.61.5 4133829e', 'osm3s': {'timestamp_osm_base': '2024-03-21T14:04:30Z', 'copyright': 'The data included in this document is from www.openstreetmap.org. The data is made available under ODbL.'}, 'elements': [{'type': 'way', 'id': 26577114, 'nodes': [291435953, 1751820952, 291435954, 1751820953, 1751820954, 1751820955, 291435955], 'tags': {'highway': 'residential', 'lit': 'yes', 'maxspeed': '30', 'maxspeed:type': 'DE:zone30', 'name': 'Rhedenstraße'}}, {'type': 'way', 'id': 26577115, 'nodes': [1558201814, 291435956], 'tags': {'highway': 'residential', 'maxspeed': '30', 'maxspeed:type': 'DE:zone30', 'name': 'Von-Ketteler-Straße'}}, {'type': 'way', 'id': 26577275, 'nodes': [291438870, 2580378582, 1647096049, 1579451712, 1558201822, 1558201815], 'tags': {'highway': 'residential', 'maxspeed': '30', 'maxspeed:type': 'DE:zone30', 'name': 'Mutter-Barat-Straße'}}, {'type': 'way', 'id': 26577276, 'nodes': [291438871, 291438872, 2580378571, 1647095991, 1647095994, 5633963168, 291438873], 'tags': {'highway': 'residential', 'lit': 'yes', 'maxspeed': '30', 'maxspeed:type': 'DE:zone30', 'name': 'Stegerwaldstraße', 'surface': 'asphalt'}}, {'type': 'way', 'id': 105196614, 'nodes': [1212226065, 1212226220, 4670199082, 4670199089], 'tags': {'access': 'private', 'highway': 'service', 'service': 'driveway'}}, {'type': 'way', 'id': 142380557, 'nodes': [1558201823, 4246007583, 1558201815, 4246007582, 1558201810, 1558201808, 1558201806, 1558201807, 1558201809, 1647096076, 1558201814, 1751820951, 1647096079, 291435953, 1558201813, 11717177703, 1558201812], 'tags': {'highway': 'residential', 'lit': 'yes', 'maxspeed': '30', 'maxspeed:type': 'DE:zone30', 'name': 'Von-Ketteler-Straße'}}, {'type': 'way', 'id': 142380558, 'nodes': [1558201806, 291435957, 1212226220, 291435958, 291435959], 'tags': {'bicycle': 'yes', 'foot': 'yes', 'highway': 'service', 'motorcar': 'private', 'motorcycle': 'private', 'name': 'Von-Ketteler-Straße', 'surface': 'asphalt'}}, {'type': 'way', 'id': 425280520, 'nodes': [4246007582, 4246007580], 'tags': {'highway': 'footway', 'surface': 'paving_stones'}}]}

roads = []
for element in data['elements']:
    if element['type'] == 'way':
        geometry = LineString([])
        road = {
            'id': element['id'],
            'name': element['tags'].get('name', 'Unknown'),
            'highway': element['tags']['highway'],
            'maxspeed': element['tags'].get('maxspeed', 'Unknown'),
            'geometry': geometry
        }
        roads.append(road)

gdf_roads = gpd.GeoDataFrame(roads, geometry='geometry')
print(gdf_roads.head())
gdf_roads.to_file("roads.shp")
          id                 name      highway maxspeed          geometry
0   26577114         Rhedenstraße  residential       30  LINESTRING EMPTY
1   26577115  Von-Ketteler-Straße  residential       30  LINESTRING EMPTY
2   26577275  Mutter-Barat-Straße  residential       30  LINESTRING EMPTY
3   26577276     Stegerwaldstraße  residential       30  LINESTRING EMPTY
4  105196614              Unknown      service  Unknown  LINESTRING EMPTY
In [21]:
import requests

def fetch_osm_data(year):
    api_url = "http://overpass-api.de/api/interpreter"
    query = f"""
    [out:json][date:"{year}-01-01T00:00:00Z"];
    (
      way["highway"]
      (50.746,7.154,50.748,7.156); // Replace with your bounding box
    );
    out body;
    """
    response = requests.post(api_url, data={'data': query})
    print("Status code:", response.status_code)
    try:
        data = response.json()
        return data
    except requests.exceptions.JSONDecodeError:
        print("Failed to decode JSON from response.")
        print(response.text[:500])
        return None
In [22]:
import geopandas as gpd
import matplotlib.pyplot as plt
from shapely.geometry import LineString

def convert_to_geodf(data):
    return gpd.GeoDataFrame({
        'osm_id': [element['id'] for element in data['elements']],
        'geometry': [LineString([]) for _ in data['elements']]  # Placeholder: Replace with actual LineStrings
    })

year = 2020
data = fetch_osm_data(year)

if data:
    gdf = convert_to_geodf(data)
    fig, ax = plt.subplots(figsize=(10, 10))
    gdf.plot(ax=ax)
    ax.set_title(f"OSM Roads Data for {year}")
    plt.show()
else:
    print("No data to visualize.")
Status code: 200
C:\Users\mvair\anaconda3\Lib\site-packages\geopandas\plotting.py:979: UserWarning: The GeoSeries you are attempting to plot is composed of empty geometries. Nothing has been displayed.
  return plot_dataframe(data, *args, **kwargs)
No description has been provided for this image
In [23]:
 
In [24]:
 
In [26]:
print(gdf.head()) 
      osm_id                                           geometry
0   26577114  LINESTRING (7.15500 50.74700, 7.15500 50.74700...
1   26577115    LINESTRING (7.15500 50.74700, 7.15500 50.74700)
2   26577275  LINESTRING (7.15500 50.74700, 7.15500 50.74700...
3   26577276  LINESTRING (7.15500 50.74700, 7.15500 50.74700...
4  105196614  LINESTRING (7.15500 50.74700, 7.15500 50.74700...
In [43]:
0
Out[43]:
0
In [45]:
import requests
import geopandas as gpd
import matplotlib.pyplot as plt
from shapely.geometry import LineString

def fetch_osm_data(year):
    api_url = "http://overpass-api.de/api/interpreter"
    query = f"""
    [out:json][date:"{year}-01-01T00:00:00Z"];
    (
      way["highway"]
      (12.920172, 80.123833, 13.240172, 80.333833);  
    );
    out body;
    """
    response = requests.post(api_url, data={'data': query})
    if response.status_code == 200:
        return response.json()
    else:
        raise ValueError(f"Failed to fetch data: HTTP {response.status_code}")


def fetch_node_coordinates(node_ids):
    api_url = "http://overpass-api.de/api/interpreter"
    query = f"""
    [out:json];
    (node(id:{",".join(map(str, node_ids))}););
    out;
    """
    response = requests.post(api_url, data={'data': query})
    if response.status_code == 200:
        data = response.json()
        coordinates = {node['id']: (node['lon'], node['lat']) for node in data['elements']}
        return coordinates
    else:
        raise ValueError(f"Failed to fetch node coordinates: HTTP {response.status_code}")


def construct_geometries(elements, node_coordinates):
    geometries = []
    for element in elements:
        if 'nodes' in element:
            coords = [node_coordinates[node_id] for node_id in element['nodes'] if node_id in node_coordinates]
            geometry = LineString(coords) if len(coords) >= 2 else None
        else:
            geometry = None
        if geometry is not None:
            geometries.append(geometry)
    return geometries


def create_geodataframe(elements, geometries):
    valid_elements = [element for element, geometry in zip(elements, geometries) if geometry is not None]
    valid_geometries = [geometry for geometry in geometries if geometry is not None]
    return gpd.GeoDataFrame({'osm_id': [element['id'] for element in valid_elements], 'geometry': valid_geometries})


def visualize_geodataframe(gdf, year):
    fig, ax = plt.subplots(figsize=(10, 10))
    gdf.plot(ax=ax)
    ax.set_title(f"OSM Roads Data for {year}")
    plt.show()

year = 2024
data = fetch_osm_data(year)
if data and 'elements' in data:
    elements = data['elements']
    node_ids = set(node_id for element in elements for node_id in element.get('nodes', []))
    node_coordinates = fetch_node_coordinates(node_ids)
    geometries = construct_geometries(elements, node_coordinates)
    gdf = create_geodataframe(elements, geometries)
    visualize_geodataframe(gdf, year)
No description has been provided for this image
In [46]:
import requests
import geopandas as gpd
import matplotlib.pyplot as plt
from shapely.geometry import LineString

def fetch_osm_data(year):
    api_url = "http://overpass-api.de/api/interpreter"
    query = f"""
    [out:json][date:"{year}-01-01T00:00:00Z"];
    (
      way["highway"]
      (50.746,7.154,50.748,7.156);
    );
    out body;
    """
    response = requests.post(api_url, data={'data': query})
    if response.status_code == 200:
        return response.json()
    else:
        raise ValueError(f"Failed to fetch data: HTTP {response.status_code}")

def fetch_node_coordinates(node_ids):
    api_url = "http://overpass-api.de/api/interpreter"
    query = f"""
    [out:json];
    (node(id:{",".join(map(str, node_ids))}););
    out;
    """
    response = requests.post(api_url, data={'data': query})
    if response.status_code == 200:
        data = response.json()
        coordinates = {node['id']: (node['lon'], node['lat']) for node in data['elements']}
        return coordinates
    else:
        raise ValueError(f"Failed to fetch node coordinates: HTTP {response.status_code}")


def construct_geometries(elements, node_coordinates):
    geometries = []
    for element in elements:
        if 'nodes' in element:
            coords = [node_coordinates[node_id] for node_id in element['nodes'] if node_id in node_coordinates]
            geometry = LineString(coords) if coords else LineString()
        else:
            geometry = LineString()
        geometries.append(geometry)
    return geometries

def create_geodataframe(elements, geometries):
    return gpd.GeoDataFrame({'osm_id': [element['id'] for element in elements], 'geometry': geometries})

def visualize_geodataframe(gdf, year):
    fig, ax = plt.subplots(figsize=(10, 10))
    gdf.plot(ax=ax)
    ax.set_title(f"OSM Roads Data for {year}")
    plt.show()

year = 2020
data = fetch_osm_data(year)
if data and 'elements' in data:
    elements = data['elements']
    node_ids = set(node_id for element in elements for node_id in element.get('nodes', []))
    node_coordinates = fetch_node_coordinates(node_ids)
    geometries = construct_geometries(elements, node_coordinates)
    gdf = create_geodataframe(elements, geometries)
    visualize_geodataframe(gdf, year)
No description has been provided for this image
In [1]:
import requests
import geopandas as gpd
from shapely.geometry import LineString
import folium

def fetch_osm_data(year):
    api_url = "http://overpass-api.de/api/interpreter"
    query = f"""
    [out:json][date:"{year}-01-01T00:00:00Z"];
    (
      way["highway"]
      (12.920172, 80.123833, 13.240172, 80.333833);  
    );
    out body;
    """
    response = requests.post(api_url, data={'data': query})
    return response.json() if response.status_code == 200 else None

def fetch_node_coordinates(node_ids):
    api_url = "http://overpass-api.de/api/interpreter"
    query = f"""
    [out:json];
    (node(id:{",".join(map(str, node_ids))}););
    out;
    """
    response = requests.post(api_url, data={'data': query})
    data = response.json() if response.status_code == 200 else None
    return {node['id']: (node['lon'], node['lat']) for node in data['elements']} if data else None

def construct_geometries(elements, node_coordinates):
    geometries = []
    for element in elements:
        coords = [node_coordinates[node_id] for node_id in element['nodes'] if node_id in node_coordinates and node_id in node_coordinates]
        if len(coords) >= 2:
            geometries.append(LineString(coords))
    return geometries

def create_geodataframe(elements, geometries):
    valid_elements = [element for element, geometry in zip(elements, geometries) if geometry]
    return gpd.GeoDataFrame({'osm_id': [element['id'] for element in valid_elements], 'geometry': geometries})

def visualize_geodataframe_with_folium(gdf, year):
    center = gdf.geometry.centroid.iloc[0].coords[0][::-1]
    m = folium.Map(location=center, zoom_start=12, tiles='OpenStreetMap')
    for _, row in gdf.iterrows():
        simplified_geom = row.geometry.simplify(tolerance=0.001, preserve_topology=True)
        folium.PolyLine(locations=[[y, x] for x, y in simplified_geom.coords], color='blue', weight=2, opacity=0.5).add_to(m)
    return m

year = 2024
data = fetch_osm_data(year)
if data and 'elements' in data:
    elements = data['elements']
    node_ids = set(node_id for element in elements for node_id in element.get('nodes', []))
    node_coordinates = fetch_node_coordinates(node_ids)
    geometries = construct_geometries(elements, node_coordinates)
    gdf = create_geodataframe(elements, geometries)
    map_display = visualize_geodataframe_with_folium(gdf, year)
    display(map_display)
Make this Notebook Trusted to load map: File -> Trust Notebook
In [2]:
import requests
import geopandas as gpd
from shapely.geometry import LineString
import folium

def fetch_osm_data(year):
    api_url = "http://overpass-api.de/api/interpreter"
    query = f"""
    [out:json][date:"{year}-01-01T00:00:00Z"];
    (
      way["highway"]
      (12.920172, 80.123833, 13.240172, 80.333833);  
    );
    out body;
    """
    response = requests.post(api_url, data={'data': query})
    return response.json() if response.status_code == 200 else None

def fetch_node_coordinates(node_ids):
    api_url = "http://overpass-api.de/api/interpreter"
    query = f"""
    [out:json];
    (node(id:{",".join(map(str, node_ids))}););
    out;
    """
    response = requests.post(api_url, data={'data': query})
    data = response.json() if response.status_code == 200 else None
    return {node['id']: (node['lon'], node['lat']) for node in data['elements']} if data else None

def construct_geometries(elements, node_coordinates):
    geometries = []
    for element in elements:
        coords = [node_coordinates[node_id] for node_id in element['nodes'] if node_id in node_coordinates and node_id in node_coordinates]
        if len(coords) >= 2:
            geometries.append(LineString(coords))
    return geometries

def create_geodataframe(elements, geometries):
    valid_elements = [element for element, geometry in zip(elements, geometries) if geometry]
    return gpd.GeoDataFrame({'osm_id': [element['id'] for element in valid_elements], 'geometry': geometries})

def visualize_geodataframe_with_folium(gdf, year):
    center = gdf.geometry.centroid.iloc[0].coords[0][::-1]
    m = folium.Map(location=center, zoom_start=12, tiles='OpenStreetMap')
    for _, row in gdf.iterrows():
        simplified_geom = row.geometry.simplify(tolerance=0.001, preserve_topology=True)
        folium.PolyLine(locations=[[y, x] for x, y in simplified_geom.coords], color='blue', weight=2, opacity=0.5).add_to(m)
    return m

year = 2015
data = fetch_osm_data(year)
if data and 'elements' in data:
    elements = data['elements']
    node_ids = set(node_id for element in elements for node_id in element.get('nodes', []))
    node_coordinates = fetch_node_coordinates(node_ids)
    geometries = construct_geometries(elements, node_coordinates)
    gdf = create_geodataframe(elements, geometries)
    map_display = visualize_geodataframe_with_folium(gdf, year)
    display(map_display)
Make this Notebook Trusted to load map: File -> Trust Notebook
In [ ]: